﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Web.Profile;
using System.IO;
using System.Text;

namespace WebSite.admin.product
{
    public partial class goods_add03 : System.Web.UI.Page
    {
        // Fields


        //// Methods
        //private void AddPicture(string imgpath, string imgnote, string albumid)
        //{
        //    SQLAccess.DoSql("insert into DB_Spe(spepic,spename,proid) values('" + imgpath + "','" + imgnote + "'," + albumid + ")");
        //}

        protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
        {
            if (base.Request.QueryString["pid"] != null)
            {
                SQLAccess.DoSql(string.Concat(new object[] { 
                "update DB_Shoppro set proorder=", this.proorder.Value == "" ? "0" : re.replace(this.proorder.Value), ",proisnew1=",  this.proisnew1.Checked  ? "1" : "0", ",proisnew2=",  this.proisnew2.Checked  ? "1" : "0", ",proisnew3=", this.proisnew3.Checked  ? "1" : "0", 
                ",proisnew4=",  this.proisnew4.Checked  ? "1" : "0",",proku1=",  this.proku1.Value ==""  ? "100" : this.proku1.Value,",proku2=",  this.proku2.Value ==""  ? "100" : this.proku2.Value,  ",proisshow=", this.proisshow.Checked  ? "1" : "0", 
                " where proid=", base.Request.QueryString["pid"], ""
             }));
                
                base.Response.Write("<script language='javascript'>alert('产品其它信息修改成功');window.location.href='goods_add03.aspx?pid=" + base.Request.QueryString["pid"] + "';</script>");
                base.Response.End();
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (this.Session["Adminlogin"] == null)
            {
                base.Response.Write("<script language=javascript>window.top.location.href='../login.aspx';</script>");
                base.Response.End();
            }
            this.ImageButton1.Attributes["onclick"] = "return clicka();";
            if (!base.IsPostBack && (base.Request.QueryString["pid"] != null))
            {
                this.upbind();
            }
        }

        private void upbind()
        {

            string sql = "select top 1 * from DB_Shoppro where proid=" + base.Request.QueryString["pid"];
            DataTable table = new DataTable();
            table = SQLAccess.GreatDs(sql).Tables[0];
            this.proisnew1.Checked = table.Rows[0]["proisnew1"].ToString() =="" ? false : (bool)table.Rows[0]["proisnew1"];
            this.proisnew2.Checked = table.Rows[0]["proisnew2"].ToString() == "" ? false : (bool)table.Rows[0]["proisnew2"];
            this.proisnew3.Checked = table.Rows[0]["proisnew3"].ToString() == "" ? false : (bool)table.Rows[0]["proisnew3"];
            this.proisnew4.Checked = table.Rows[0]["proisnew4"].ToString() == "" ? false : (bool)table.Rows[0]["proisnew4"];
            this.proisshow.Checked = (bool)table.Rows[0]["proisshow"];
            this.proku1.Value = table.Rows[0]["proku1"].ToString();
            this.proku2.Value = table.Rows[0]["proku2"].ToString();

            this.proorder.Value = table.Rows[0]["proorder"].ToString();
            if (((base.Request.QueryString["speid"] != null) && (base.Request.QueryString["action"] != null)) && (base.Request.QueryString["action"].ToString() == "del"))
            {
                SQLAccess.DoSql("delete from DB_Spe where speid=" + base.Request.QueryString["speid"].ToString() + "");
                base.Response.Write("<script language='javascript'>window.location.href='goods_add03.aspx?pid=" + base.Request.QueryString["pid"] + "';</script>");
                base.Response.End();
            }
        }

        private void upcontent(string albumid)
        {
            string sql = "select * from DB_Spe where proid=" + albumid + " order by speid asc";
            DataTable table = new DataTable();
            table = SQLAccess.GreatDs(sql).Tables[0];
            if (table.Rows.Count > 0)
            {
                foreach (DataRow row in table.Rows)
                {
                    SQLAccess.DoSql("update [DB_Spe] set [spename]='" + base.Request.Form["content_" + row["speid"].ToString()] + "' where speid=" + row["speid"].ToString() + "");
                }
            }
        }


    }
}